class SyncWaterfallHook { // 钩子 是同步的

  constructor(args) { // args => ['name']
    this.tasks = [];

  }

  tap(name, task) {// 事件名字 事件方法
    this.tasks.push(task);
  }

  call(...args) {
    let [first, ...others] = this.tasks;
    let ret = first(...args);
    others.reduce((a, b) => {
      return b(a);
    }, ret);
  }

}

let hook = new SyncWaterfallHook(['name']);
hook.tap('react', function (name) {
  console.log('react', name);
  return 'react ok';
});

hook.tap('vue', function (name) {
  console.log('vue', name);
  return 'vue ok';
});

hook.tap('angular', function (name) {
  console.log('angular', name);
  return 'angular ok';
});

hook.call('gzw');
